﻿Imports System.Xml
Imports System.IO

Public Class frmMain

    Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Sets the Titles
        Dim title As String = "Dice Bag"
        Dim gbTitle As String = "Options"

        Me.Text = title
        gbOptions.Text = gbTitle

        'Loads XML File
        Dim xmlr As XmlReader = XmlReader.Create("Dice Bag.xml")

        'Reads XML Document
        Do While xmlr.Read()
            If xmlr.NodeType = XmlNodeType.Element AndAlso xmlr.Name = "DiceInfo" Then
                cbDiceType.Items.Add(xmlr.GetAttribute(0))
            End If
        Loop
    End Sub

    Private Sub miExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles miExit.Click
        'Exit the Application
        Me.Close()

    End Sub

    Private Sub miClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles miClear.Click
        'Clears the List of Rolls
        lvRollList.Clear()

    End Sub

    Private Sub btnRollDice_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRollDice.Click
        'Checks for Qty of Dice to be rolled
        If tbDiceQty.Text = vbNullString Then

            'Displays message box if number of dice is not supplied
            Do
                MsgBox("Please enter a value for the number of dice to be rolled" & vbNewLine & "Enter a value of 1 or greater", MsgBoxStyle.OkOnly, "Dice Quantity")
                Exit Do
            Loop
        Else
            'MsgBox("Code Complete!!", MsgBoxStyle.OkOnly)

            'Assigns the Dice Qty
            diceQty = CInt(tbDiceQty.Text)

            'Checks for selected dice
            If cbDiceType.Text = vbNullString Then

                'Displays a message box if a dice is not chosen
                Do
                    MsgBox("Please select a dice to be rolled from the drop-down menu", MsgBoxStyle.OkOnly, "Dice Quantity")
                    Exit Do
                Loop
            Else

                'Get the number of sides for the dice rolled
                Call modMain.numSides()

                'Rolls Dice
                Call modMain.rollDice()

            End If
        End If
    End Sub
End Class